#ifndef SIMPLEAPP8_H_
#define SIMPLEAPP8_H_

#include "CEGuiD3D10BaseApplication.h"
#include "model_obj.h"


class SimpleApp: public CEGuiD3D10BaseApplication
{
    D3DXMATRIX                  g_World;
    D3DXMATRIX                  g_World2;
    D3DXMATRIX                  g_View;
    D3DXMATRIX                  g_Projection;

    ModelOBJ *m, *m2;

public:

    void initMatrix()
    {
        // Initialize the world matrices
        D3DXMatrixIdentity( &g_World );
        //D3DXMatrixIdentity( &g_World2 );

        D3DXMatrixTranslation(&g_World2, 0, 0, 1);

        RECT rc;
        GetClientRect( pimpl->d_window, &rc );
        UINT width = rc.right - rc.left;
        UINT height = rc.bottom - rc.top;

        // Initialize the projection matrix
        D3DXMatrixPerspectiveFovLH( &g_Projection, ( float )D3DX_PI * 0.25f, 
            width / ( FLOAT )height, 0.1f, 100.0f );
    }

    void createCamera()
    {
        // Initialize the view matrix
        D3DXVECTOR3 position( 0.0f, 1.0f, 3.0f );
        D3DXVECTOR3 lookAt( 0.0f, 0.0f, 0.0f );
        m_camera = new BvCamera(position, lookAt);
        g_View = m_camera->GetViewMatrix();
    }

    HRESULT createScene()
    {
        bvRenderer = new BvD3D10Renderer(pimpl->d_device);
        m = new ModelOBJ(bvRenderer);

        m->import("../models/triangle.obj");

        m->setEffect("TransparencyShader.fx", "RenderSolid");

        m2 = new ModelOBJ(*m);

        initMatrix();

        bvRenderer->setEffectVariableByName(0, "View", 
            EFFECT_VARIABLE_MATRIX, ( float* )&g_View);
        bvRenderer->setEffectVariableByName(0, "Projection", 
            EFFECT_VARIABLE_MATRIX, ( float* )&g_Projection);
        return S_OK;
    }

    void drawPerFrame()
    {
        // Update our time
        static float t = 0.0f;
        int g_driverType = 0;
        if( g_driverType == D3D10_DRIVER_TYPE_REFERENCE )
        {
            t += ( float )D3DX_PI * 0.0125f;
        }
        else
        {
            static DWORD dwTimeStart = 0;
            DWORD dwTimeCur = GetTickCount();
            if( dwTimeStart == 0 )
                dwTimeStart = dwTimeCur;
            t = ( dwTimeCur - dwTimeStart ) / 5000.0f;
        }

        // Rotate cube around the origin
        D3DXMatrixRotationZ( &g_World, t );

        bvRenderer->setEffectVariableByName(0, "World", 
            EFFECT_VARIABLE_MATRIX, ( float* )&g_World);

        m->draw();

        bvRenderer->setEffectVariableByName(0, "World", 
            EFFECT_VARIABLE_MATRIX, ( float* )&g_World2);
        m2->draw();
    }

};

#endif //SIMPLEAPP8_H_
